package web.demo.service.impl;

import java.util.List;

import web.demo.dao.impl.FoodTypeDao;
import web.demo.entity.Food;
import web.demo.entity.FoodType;
import web.demo.factory.BeanFactory;
import web.demo.service.IFoodTypeService;
import web.demo.utils.Condition;
import web.demo.utils.PageBean;
/**
 * 业务逻辑层
 * */
public class FoodTypeService implements IFoodTypeService{
	
	private FoodTypeDao foodTypeDao=BeanFactory.getInstance("foodTypeDao", FoodTypeDao.class );
	private FoodService foodService=BeanFactory.getInstance("foodService",FoodService.class);
	
	@Override
	public boolean addFoodType(FoodType foodType) {
		
		return foodTypeDao.addFoodType(foodType);
	}

	@Override
	public List<FoodType> getAll() {
		return foodTypeDao.getAll();
	}

	@Override
	public FoodType getById(String id) {
		//对页面传来的id进行转化
		int foodId=Integer.parseInt(id);
		return foodTypeDao.getById(foodId);
	}

	@Override
	public void update(FoodType foodType) {
		foodTypeDao.update(foodType);
	}

	@Override
	public boolean delete(String id,String appPath, String sysPath) {
		int foodTypeId=Integer.parseInt(id);
		//根据菜系查询所有菜品，删除所有菜品下的照片
		List<Food> foodList=foodService.getByFoodType(foodTypeId);
		for(Food food:foodList){
			foodService.delete(food.getId(),appPath,sysPath);
		}
		return foodTypeDao.delete(foodTypeId);
	}

	@Override
	public List<FoodType> select(String str) {
		return foodTypeDao.select(str);
	}

}
